#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
LL a[N];
int n, c;
int main()
{
	cin >> n >> c;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	LL ret = 0;
	for(int i = 1; i <= n; i++)
	{
		LL b =  a[i] - c;
		auto left = lower_bound(a + 1, a + 1 + n, b);
		auto right = upper_bound(a + 1, a + 1 + n, b);
		ret += right - left;
	}
	cout << ret << endl;
	return 0;
}

